package com.lulalei.dbviewer.commons.api;

import lombok.Data;

/**
 * <p>
 *     通用结果返回
 * </p>
 *
 * @author lulalei
 * @create 2021-05-14 20:51
 */
@Data
public class ResultBean<T> {
    private int code;
    private String msg;
    private T data;

    private ResultBean(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static<T> ResultBean<T> success(){
        return new ResultBean<T>(20000,"操作成功",null);
    }

    public static<T> ResultBean<T> success(T data){
        return new ResultBean<T>(20000,"操作成功",data);
    }

    public static<T> ResultBean<T> failure(String msg){
        return new ResultBean<T>(50000,msg,null);
    }

    public static<T> ResultBean<T> failure(){
        return new ResultBean<T>(50000,"操作失败",null);
    }

    public static<T> ResultBean<T> build(int code, String msg, T data){
        return new ResultBean<T>(code,msg,data);
    }

    public static<T> ResultBean<T> build(int code, String msg){
        return new ResultBean<T>(code,msg,null);
    }
}
